package com.xtaller.core.format;


import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;


/**
 * @author Tanj
 * @create 2017-07-14 9:34
 */
public class R {
    public static ResponseEntity data(M m){
        return new ResponseEntity(m,formatStatus(0));
    }
    public static ResponseEntity data(int status,M m){
        return new ResponseEntity(m,formatStatus(status));
    }
    public static ResponseEntity data(int status,String message){
        return new ResponseEntity(M.data(message),formatStatus(status));
    }
    public static ResponseEntity data(HttpStatus status,String message){
        return new ResponseEntity(M.data(message),status);
    }

    private static HttpStatus formatStatus(int status){
        switch (status){
            case 400 :
                return HttpStatus.BAD_REQUEST;
            case 401 :
                return HttpStatus.UNAUTHORIZED;
            case 402 :
                return HttpStatus.PAYMENT_REQUIRED;
            case 403 :
                return HttpStatus.FORBIDDEN;
            case 404 :
                return HttpStatus.NOT_FOUND;
            case 405 :
                return HttpStatus.METHOD_NOT_ALLOWED;
            case 406 :
                return HttpStatus.NOT_ACCEPTABLE;
            case 407 :
                return HttpStatus.PROXY_AUTHENTICATION_REQUIRED;
            case 408 :
                return HttpStatus.REQUEST_TIMEOUT;
            case 411 :
                return HttpStatus.LENGTH_REQUIRED;
            case 412 :
                return HttpStatus.PRECONDITION_FAILED;
            case 413 :
                return HttpStatus.PAYLOAD_TOO_LARGE;
            case 423 :
                return HttpStatus.LOCKED;
            case 500 :
                return HttpStatus.INTERNAL_SERVER_ERROR;
            case 502 :
                return HttpStatus.BAD_GATEWAY;
            case 504 :
                return HttpStatus.GATEWAY_TIMEOUT;
            default:
                return HttpStatus.OK;
        }
    }

}
